package com.song.boot.springstudy.sort.str;

import java.util.ArrayList;
import java.util.List;

public class RabinKarpV2 {


    public static void main(String[] args) {
        // 实际例子：在文本中查找模式串"ab"
        String text = "abracadabra";
        String pattern = "ab";
        // 子串长度
        int subLength = 2;
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i <= text.length() - subLength; i++) {
            // 获取从索引i开始，长度为2的子串
            String substring = text.substring(i, i + subLength);
            result.add(substring.hashCode());
            System.out.println(substring.hashCode());
        }
        System.out.println("---------------");
        System.out.println(pattern.hashCode());

        List<Integer> weizi = new ArrayList<>();

        for (int i = 0; i < result.size(); i++) {
            if (result.get(i)==pattern.hashCode()) {
                weizi.add(i);
            }
        }


        System.out.println("文本: " + text);
        System.out.println("模式串: " + pattern);
        System.out.println("匹配位置: " + weizi);
    }
}
